package com.qwe.graduation.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import com.qwe.graduation.service.ICollectService;
import com.qwe.graduation.entity.Collect;


/**
 * <p>
 * 收藏表 前端控制器
 * </p>
 *
 * @author 林卓锋
 * @since 2023-01-08
 */
@RestController
@RequestMapping("/collect")
public class CollectController {

    @Resource
    private ICollectService collectService;

    //新增或更改
    @PostMapping
    public Boolean save(@RequestBody Collect collect) {
        return collectService.saveOrUpdate(collect);
    }

    //删除
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable String id) {
        return collectService.removeById(id);
    }

    //查找全部
    @GetMapping
    public List<Collect> findAll() {
        return collectService.list();
    }

    //根据id查询
    @GetMapping("/{id}")
    public List<Collect> findOne(@PathVariable String id) {
        return collectService.list();
    }

    //批量删除
    @PostMapping("/delete/Beatch")
    public Boolean deleteBeatch(@RequestBody List<String> ids) {
        return collectService.removeByIds(ids);
    }

    //分页
    @GetMapping("/page")
    public Page<Collect> findPage(@RequestParam Integer pageNum,
                                  @RequestParam Integer pageSize) {
        return collectService.page(new Page<>(pageNum, pageSize));
    }

        public static void main(String[] args) {
                for (int i = 0; i < 10; i++) {
                        System.out.println(IdWorker.getId());//雪花算法
                }
        }

}

